package com.smart.draw.plantuml.controllers;

import jakarta.servlet.ServletResponse;
import net.sourceforge.plantuml.klimt.color.HColorSet;
import net.sourceforge.plantuml.skin.SkinParam;
import net.sourceforge.plantuml.syntax.LanguageDescriptor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.PrintStream;
import java.util.Collection;
import java.util.Set;

/**
 * @Author xiaoqiang
 * @Version LanguageController.java, v 0.1 2025年08月26日 16:53 xiaoqiang
 * @Description: TODO
 */
@RestController
@RequestMapping("/language")
public class LanguageController {

    private static final LanguageDescriptor languageDescriptor = new LanguageDescriptor();

    @GetMapping(produces = MediaType.TEXT_PLAIN_VALUE)
    public void index(ServletResponse response) throws IOException {
        languageDescriptor.print(new PrintStream(response.getOutputStream()));
    }

    @GetMapping("types")
    public Set<String> indexType() {
        return languageDescriptor.getType();
    }

    @GetMapping("keywords")
    public Set<String> indexKeywords() {
        return languageDescriptor.getKeyword();
    }

    @GetMapping("preprocessors")
    public Set<String> indexPreprocessor() {
        return languageDescriptor.getPreproc();
    }

    @GetMapping("skin-parameters")
    public Collection<String> indexSkinParameter() {
        return SkinParam.getPossibleValues();
    }

    @GetMapping("colors")
    public Collection<String> indexColors() {
        return HColorSet.instance().names();
    }

}
